home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / Demos / DuelVoice / gameproc.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  6.9 KB  |  227 lines

  1. //-----------------------------------------------------------------------------
  2. // File: GameProc.h
  3. //
  4. // Desc: Game processing routines
  5. //
  6. // Copyright (C) 1995-2001 Microsoft Corporation. All Rights Reserved.
  7. //-----------------------------------------------------------------------------
  8. #define IDIRECTPLAY2_OR_GREATER
  9. #include <ddraw.h>
  10. #include <dplay.h>
  11. #include <dsound.h>
  12.  
  13. // align on single byte boundaries
  14. // this is a stop-gap measure until the structures can be re-arranged.
  15. #pragma pack(1)
  16.  
  17. #define MAX_SHIP_X     (MAX_SCREEN_X - 32)
  18. #define MAX_SHIP_Y     (MAX_SCREEN_Y - 32)
  19. #define MAX_SHIP_FRAME 40
  20. #define MAX_BULLET_X    (MAX_SCREEN_X - 3)
  21. #define MAX_BULLET_Y    (MAX_SCREEN_Y - 3)
  22. #define MAX_BULLET_FRAME 400
  23.  
  24. #define NUM_SHIP_TYPES 4
  25.  
  26. #define DEF_SHOW_DELAY     (2000)
  27. #define MAX_BUFFER_SIZE    256
  28.  
  29. #define UPDATE_INTERVAL     40      // interval between position updates in milliseconds (25 FPS)
  30. #define SYNC_INTERVAL       1000    // synchronize once every second
  31. #define HIDE_TIMEOUT        5000    // time for which a ship is disabled after a hit
  32.  
  33. // Keyboard commands
  34. #define KEY_STOP        0x00000001l
  35. #define KEY_DOWN        0x00000002l
  36. #define KEY_LEFT        0x00000004l
  37. #define KEY_RIGHT       0x00000008l
  38. #define KEY_UP          0x00000010l
  39. #define KEY_FIRE        0x00000020l
  40. #define KEY_ENGINEOFF   0x00000040l
  41.  
  42. // Offsets for the bullet bitmap
  43. #define     BULLET_X    304
  44. #define     BULLET_Y    0
  45.  
  46. struct FRAG
  47. {
  48.     double      dPosX;
  49.     double      dPosY;
  50.     LPDIRECTDRAWSURFACE pdds;
  51.     RECT        src;
  52.     double      dVelX;
  53.     double      dVelY;
  54.     BOOL        valid;
  55. };
  56.  
  57. struct SHIP
  58. {
  59.     double              dPosX, dPosY;               // ship x and y position
  60.     double              dBulletPosX, dBulletPosY;   // bullet x and y position
  61.     DWORD               dwBulletFrame;              // bullet frame
  62.     char                cFrame;                     // current ship frame
  63.     BYTE                byType;                     // ship type 
  64.     BOOL                bEnable;                    // is this ship active?
  65.     BOOL                bBulletEnable;              // Is there an active bullet?
  66.  
  67.     double              dVelX, dVelY;               // ship x and y velocity (pixels/millisecond)
  68.     double              dBulletVelX, dBulletVelY;   // bullet x and y velocity (pixels/millisecond)
  69.     DWORD               dwScore;                    // current score
  70.     DWORD               dwLastTick;                 // most recent time stamp
  71.     BOOL                bIgnore;                    // flag used to synchronize ship explosions
  72.     int                 iCountDown;                 // enable time-out            
  73.     DWORD               dwFrameCount;               // number of frames since beginning of time
  74.  
  75.     // DSound members 
  76.     DWORD                 dwKeys;                  // the keyboard state
  77.     BOOL                  bEngineRunning;          // These BOOLs keep track of the ship's
  78.     BOOL                  bMoving;                 //   last condition so we can play sounds
  79.     BOOL                  bBounced;                //   when they change
  80.     BOOL                  bBlockHit;
  81.     BOOL                  bDeath;
  82.     BOOL                  bFiring;
  83.  
  84.     // DPlayVoice 
  85.     LPDIRECTSOUND3DBUFFER pDSBVoice;            // 3D buffer for the voice
  86.     DPID                  dpidID;
  87. };
  88.  
  89. struct BLOCKS
  90. {
  91.     BYTE bits[30][5];
  92. };
  93.  
  94.  
  95.  
  96.  
  97. //-----------------------------------------------------------------------------
  98. // communication packet structures
  99. //-----------------------------------------------------------------------------
  100. #define MSG_HOST        0x11    // message containing field layout, sent by host
  101. #define MSG_BLOCKHIT    0x22    // block hit message
  102. #define MSG_SHIPHIT     0x33    // ship hit message
  103. #define MSG_ADDBLOCK    0x44    // add block message
  104. #define MSG_CONTROL     0x55    // game keys message
  105. #define MSG_SYNC        0x66    // synchronization message containing the rendezvous location
  106.  
  107. struct GENERICMSG
  108. {
  109.     BYTE byType;
  110. };
  111.  
  112. struct OLDHOSTMSG
  113. {
  114.     BYTE byType;
  115.     BLOCKS Blocks;
  116. };
  117.  
  118. struct HOSTMSG
  119. {
  120.     BYTE        byType;
  121.     BLOCKS      Blocks;
  122.     int         usedShipTypes[NUM_SHIP_TYPES];
  123. };
  124.  
  125. struct BLOCKHITMSG
  126. {
  127.     BYTE        byType;
  128.     BYTE        byRow;
  129.     BYTE        byCol;
  130.     BYTE        byMask;
  131. };
  132.  
  133. struct SHIPHITMSG
  134. {
  135.     BYTE        byType;
  136.     DPID        Id;
  137. };
  138.  
  139. struct ADDBLOCKMSG
  140. {
  141.     BYTE        byType;
  142.     BYTE        byX;
  143.     BYTE        byY;
  144. };
  145.  
  146. struct CONTROLMSG
  147. {
  148.     BYTE        byType;
  149.     BYTE        byState;
  150. };
  151.  
  152. struct SYNCMSG
  153. {
  154.     BYTE        byType;
  155.     BYTE        byShipType;     // this is needed only when sends are unreliable
  156.     char        cFrame;
  157.     double      dPosX;
  158.     double      dPosY;
  159. };
  160.  
  161.  
  162.  
  163.  
  164. //-----------------------------------------------------------------------------
  165. // Prototypes
  166. //-----------------------------------------------------------------------------
  167. VOID    LaunchGame();
  168. VOID    ExitGame();
  169. HRESULT InitOurShip();
  170.  
  171. HRESULT InitLocalSoundData();
  172. HRESULT InitPlayerLocalSoundData( SHIP* pShip );
  173. BOOL WINAPI SetPlayerLocalSoundDataCB( DPID dpId, DWORD dwPlayerType,
  174.                                        LPCDPNAME pName, DWORD dwFlags,
  175.                                        VOID* pContext );
  176.  
  177. VOID    ReleaseLocalData();
  178. HRESULT ReleasePlayerLocalSoundData( SHIP* pShip );
  179. BOOL WINAPI ReleasePlayerLocalDataCB( DPID dpId, DWORD dwPlayerType,
  180.                                       LPCDPNAME pName, DWORD dwFlags,
  181.                                       VOID* pContext );
  182.  
  183. VOID    UpdateState( SHIP* pShip, DWORD dwControls );
  184. VOID    SendSync( SHIP* pShip );
  185. VOID    UpdateDisplayStatus( SHIP* pShip );
  186. VOID    UpdatePosition( DPID dpId, SHIP* ship );
  187. BOOL    IsHit( int x, int y );
  188. VOID    InitField();
  189. BOOL    setBlock( int x, int y );
  190. VOID    AddFrag( SHIP* pShip, int offX, int offY );
  191. VOID    UpdateFragment( int i );
  192. VOID    DestroyShip( SHIP* pShip );
  193. VOID    DestroyGame();
  194. BOOL    UpdateFrame();
  195.  
  196. VOID    ProcessSoundFlags( SHIP* pShip );
  197. BOOL WINAPI RenderPlayerCB( DPID dpId, DWORD dwPlayerType, LPCDPNAME pName, 
  198.                             DWORD dwFlags, VOID* pContext );
  199. BOOL    DrawScreen();
  200. BOOL    DrawScore();
  201. VOID    DrawShip( SHIP* pShip );
  202. VOID    DrawBlock( int x, int y );
  203. VOID    DrawBullet( SHIP* pShip );
  204. VOID    DrawFragments();
  205. VOID    DisplayFrameRate();
  206.  
  207. VOID    GetConnection();
  208. HRESULT ReceiveMessages();
  209. VOID    DoSystemMessage( DPMSG_GENERIC* pMsg, DWORD dwMsgSize, DPID idFrom,
  210.                          DPID idTo );
  211. VOID    DoApplicationMessage( GENERICMSG* pMsg, DWORD dwMsgSize, DPID idFrom,
  212.                               DPID idTo );
  213. VOID    SendGameMessage( GENERICMSG* pMsg, DPID idTo );
  214. VOID    CleanupComm();
  215.  
  216.  
  217. HRESULT InitializeGameSounds();
  218. VOID    CleanupGameSounds();
  219.  
  220.  
  221.  
  222. // restore default alignment
  223. #pragma pack()
  224.  
  225.  
  226.  
  227.